package com.hd.netty.init;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @Author: hzhh123
 * @Date: 2018/12/16 16:02
 * 继承了AfterSpringBegin的子类在spring加载成功后，会自动启动
 */
public class AfterSpringBegin extends TimerTask implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void run() {

    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if(event.getApplicationContext().getParent() ==null){
            Timer timer = new Timer();
            timer.schedule(this, 0);
        }
    }
}
